import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
import { NavController } from '@ionic/angular';

@Component({
  selector: 'key-deployment',
  templateUrl: './key-deployment.html',
  styleUrls: ['key-deployment.scss']
})
export class DeploymentComponent implements OnInit, OnChanges {
  @Input() roomInfo;
  @Input() defaultSet;
  @Input() installData;

  Step;
  constructor(private navCtrl: NavController) {
  }

  // 设置初始步骤
  ngOnInit() {
    this.Step = {
      now: 0,
      state: 1
    };
  }

  ngOnChanges(changes: SimpleChanges) {
    if (this.installData) {
      if (this.installData.step) {
        for (let i = 0; i < this.defaultSet.length; i++) {
          if (i <= this.installData.step) {
            this.defaultSet[i].now = i;
            this.defaultSet[i].state = 0;
          }
          if (i < this.installData.step) {
            this.defaultSet[i].finished = true;
          }
          if (this.installData.step === 6) {
            this.defaultSet[6].finished = true;
          }
        }
      }
    }
  }

  // 进度条切换显示
  NextNum(x) {
    if (x < 6) {
      for (let i = 0; i < this.defaultSet.length; i++) {
        if (i === x + 1) {
          this.defaultSet[i].now = i;
          this.defaultSet[i].state = 0;
        }
        if (i === x) {
          this.defaultSet[i].finished = true;
        }
      }
    } else {
      this.navCtrl.navigateBack('tabs/my/InstrumentPage');
    }
  }
}
